﻿$(function() {
	/**
	 * 切换设备
	 * */
	//加载生产线树结构
    $("#switchbtn").click(function(){
    	var mePanel = $('#switchEquip');
   		mePanel.dialog('open');
   		$("#linetree").tree({
			url: basePath+"/lineConfig/generateTree.json",
			method: 'get',
			lines: true,
			onLoadSuccess: function (node, data) {
			    if (data.length > 0) {
			          //找到第一个元素
			          var n = $('#linetree').tree('find', data[0].children[0].id);
			          //调用选中事件
			          $('#linetree').tree('select', n.target);
			          $('#lines_data').datagrid({    
			  		    url: basePath+"/equip/findByLine.json",
			  		    method: 'get',
			  		    striped : true,
			  			nowrap : true,
			  			rownumbers : true,
			  			fitColumns : true,
			  			singleSelect:true,
			  			border:false,
			  			scrollbarSize:1,
			  			title:'设备',
			  			queryParams:{lineId:n.id},
			  		    columns:[[
			  		    	{field:'equNo',align:'center','title':'设备编号',width:150},
							{field:'equName',align:'center','title':'设备名称',width:120},
							{field:'type',align:'center','title':'设备类型',width:100},
							{field:'ratedPower',align:'center','title':'额定功率',width:70},
							{field:'supplier',align:'center','title':'生产厂家',width:90},
							{field:'life',align:'center','title':'使用寿命',width:70}
			  		    ]],
			  		    pagination : true,
			  	  		pageList : [5,10],
			  	  		pageNumber : 1,
			  			pageSize : 10,
			  	  		pagePosition : 'bottom'
			  		});
			          $('#lines_data').datagrid('getPanel').panel('setTitle',n.text);
	             }
	        } 
		});
    });
});